<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>


  <script>

    //1、创建ajax对象
    var xhr = new XMLHttpRequest();

    //2、监听ajax对象状态变化
    xhr.onreadystatechange = function () {

      if (this.readyState === 4 && this.status === 200) {
        console.log('this.responseText ==> ', this.responseText);
      }

    }

    //3、建立服务器连接
    xhr.open('POST', 'http://api.tianapi.com/txapi/tianqi/index', true);

    //设置post请求头, 需要调用send方法之前设置
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');

    //4、发起请求, post请求体的参数需要send方法的参数里
    xhr.send('key=05c9c231654fad19051ce388d3a14002&city=广州');

  </script>
  
</body>
</html>